package com.japp.sys.web;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import com.japp.base.BaseAction;
import com.japp.sys.bean.DpBean;
import com.japp.sys.bean.SelectBean;
import com.japp.sys.service.DpService;
import com.japp.tools.common.Common;
import com.japp.tools.common.JappLog;
@Scope("prototype")
@Controller
public class DpAction extends BaseAction<DpBean> {

	private static final long serialVersionUID = 1L;
	@Autowired
	private DpService dpService;
	private DpBean dp = new DpBean();
	
	/**
	 * 查询所有部门
	 * @return
	 */
	public String queryDpAll() {
		return SUCCESS;
	}
	/**
	 * 分页查询
	 * @return
	 */
	public String queryDp(){
		page = dpService.getPage(page, dp);
		return SUCCESS;
	}
	/**
	 * 查询部门（ID）
	 * @return
	 */
	public String findDpById() {
		return SUCCESS;
	}
	/**
	 * 更新部门
	 * @return
	 */
	public void updateDpById() {
		int rel = 0;
		if(dp.getDp_id()!=0){
			rel = dpService.updateDp(dp);
		}
		if(rel==999){
			result = "部门“"+dp.getDp_name()+"”已存在!";
		}else if(rel!=0){
			result = "部门修改成功!";
		}else{
			result = "部门修改失败!";
		}
		wPrint(result);
	}
	/**
	 * 添加部门
	 * @return
	 */
	public void insertDpById() {
		int rel = dpService.insertDp(dp);
		if(rel==999){
			result = "部门“"+dp.getDp_name()+"”已存在!";
		}else if(rel!=0){
			result = "部门“"+dp.getDp_name()+"”新增成功!";
		}else{
			result = "部门“"+dp.getDp_name()+"”新增是失败!";
		}
		wPrint(result);
	}
	/**
	 * 删除部门
	 * @return
	 */
	public void deleteDpById() {
		int rel = dpService.deleteDpById(keys);
		if(rel!=0){
			result = "部门删除成功!";
		}else{
			result = "部门删除失败!";
		}
		wPrint(result);
	}
	
	public void getJsonDpId(){
		try {
			List<SelectBean> list = dpService.queryDpSelectAll();		//部门
			json_val = Common.formtSelectToJson(list);
		} catch (Exception e) {
			JappLog.log.error("查询部门或转换Json错误",e);
		}
		wPrint(json_val);
	}
	
	public void getJsonDpCode(){
		try {
			List<SelectBean> list = dpService.queryDpSelectAllCode();		//部门
			json_val = Common.formtSelectToJson(list);
		} catch (Exception e) {
			JappLog.log.error("查询部门或转换Json错误",e);
		}
		wPrint(json_val);
	}
	public DpBean getDp() {
		return dp;
	}
	public void setDp(DpBean dp) {
		this.dp = dp;
	}
	
}
